// ActionScript file
package com.skt.common_hr.common.utilSilver
{
	import com.wcl.components.HanDateField;
	import com.wcl.utils.DateUtil;
	
	import flash.net.URLRequest;
	import flash.net.URLRequestMethod;
	import flash.net.URLVariables;
	import flash.net.navigateToURL;
	
	import mx.collections.ArrayCollection;
	import mx.containers.HBox;
	import mx.containers.VBox;
	import mx.controls.Button;
	import mx.controls.CheckBox;
	import mx.controls.ComboBox;
	import mx.controls.DateField;
	import mx.controls.RadioButton;
	import mx.controls.RadioButtonGroup;
	import mx.controls.TextInput;
	import mx.formatters.DateFormatter;
	
	public class textSilver
	{
		public static function chgDateStringSap_To_Int(val:String):int {
			var sDate:Date = DateUtil.stringToDateTime(val);
			var iDate:int = parseInt(DateUtil.toBasicString(sDate));
			
			return iDate;
		}
		
		public static function setUImode(ar:Array, mode:Boolean = false):void {
			for(var i :int=0; i<ar.length; i++) {
				if(ar[i] is TextInput) {
					if(mode==false) {
						ar[i].setStyle("borderStyle", "none");	
					}
					else {
						ar[i].setStyle("borderStyle", "solid");
					}
					ar[i].editable = mode;																
				}
				else if(ar[i] is ComboBox || CheckBox || RadioButton || Button || DateField || HanDateField) {
					ar[i].enabled = mode;
				}
				else if(ar[i] is HBox || VBox){
					ar[i].mouseChildren = mode;
					ar[i].mouseEnabled = mode;
				}
			}
		}
		
		public static function setUIclear(ar:Array):void {
			for(var i :int=0; i<ar.length; i++) {
				if(ar[i] is TextInput) {
					ar[i].text = "";																
				}
				else if(ar[i] is ComboBox ) {
					ar[i].selectedIndex = -1;
				}
				else if(ar[i] is DateField || ar[i] is HanDateField ) {
					ar[i].selectedDate = new Date();
				}			
				else if(ar[i] is RadioButtonGroup ) {
					RadioButtonGroup(ar[i]).selection  = RadioButtonGroup(ar[i]).getRadioButtonAt(0);
				}									
			}				
		}
		
		
		public static function openNavigateToURL(url:String, params:URLVariables):void {	
			var option:String = "toolbar=no,menubar=no" +
					", location=no, directions=no" 	+ 
					", scrollbars=yes, status=no"	+
					", width=300" +
					", height=760";


        	var request:URLRequest = new URLRequest(url);
	//		var request:URLRequest = new URLRequest("javascript:window.open('"+url+"',"+option+"');");

        	request.method = URLRequestMethod.POST;
        	request.data  = params;

   			navigateToURL(request, "_blank");
		}
		
		private static var dateFormatter:DateFormatter = new DateFormatter();
		public  static function toDotSpaceString(src:Date=null):String
		{
			if(src==null) {
				src = new Date()
			}			
			dateFormatter.formatString = "YYYY. MM. DD"; 
			return dateFormatter.format(src);
		}
		public  static function toDotKorString(src:Date=null):String
		{
			if(src==null) {
				src = new Date()
			}
			dateFormatter.formatString = "YYYY년 MM월 DD일"; 
			return dateFormatter.format(src);
		}		
		
		public static function regnoFunc(val:String):String {
			//730601 1060915
			if(val == null || val == '') {
				val = '';
			}
			val = val.substring(0, 6) + "-" + val.substring(6, 13)  
			return val;
		}

		public static function regnoFunc2(val:String):String {
			//730601 1060915
			if(val == null || val == '') {
				val = '';
			}
			val = val.substring(0, 6) + "-*******";  
			return val;
		}
		
		public static function B_regnoFunc(val:String):String {
			//2158548685
			if(val == null || val == '') {
				val = '';
			}
			val = val.substring(0, 3) + "-" + val.substring(3,5)+"-" + val.substring(5, 10);  
			return val;
		}
		
		public static function pernrFunc(val:String):String {			
			if(val == null || val == '') {
				val = '';
			}
			val = parseInt(val).toString();  
			return val;
		}
				
		public static function toJsonType(vo:Object):Object {
			var retObj:Object = new Object;
			for(var field:String in vo) {
				if(vo[field] is Date) {
					retObj[field] = DateUtil.toBasicString(vo[field]);
				}
				else {
					retObj[field] = vo[field];
				}
				trace(retObj[field]);
			}
			return retObj;
		}

		public static function replaceAll(arg:String):int
		{
			var i:int = 0;
			arg = arg.replace(/,/g, "");
			i = parseInt(arg);
			return i;
		}
		public static function replaceAllToFrom(arg:String, fromVal:String, toVal:String):String
		{
			var findCarriageReturnRegExp:RegExp = new RegExp("\r", "gi");
			arg = arg.replace(findCarriageReturnRegExp, toVal);
			return arg;
		}
		public static function moneyTextToInt(arg:String):int
		{
			var i:int = 0;
			arg = arg.replace(/,/g, "");
			i = parseInt(arg);
			return i;
		}

		public static function isNull_0(arg:String):Boolean
		{
			if(arg != null && arg != "0" && arg != "" ) {
				return false;
			}else {
				return true;
			}
		}

		// 콤보박스의 idx를 찾기 위해서. 
		public static function cbIndexOf(target:ArrayCollection, field:String, search:*):int
		{
			if(target != null) {
				for(var i:int; i<target.length; i++) {
					if(target.getItemAt(i)[field] == search) {
						return i;
					}
				}
			}
			return 0;
		}	
		
		// 콤보박스의 idx를 찾기 위해서. 
		public static function cbIndexOf2(target:ArrayCollection, field:String, search:*, reAc:ArrayCollection=null):int
		{
			if(reAc!=null && target==null && search !=null) {
				target = reAc;
			}
			
			if(target != null && search != "") {
				for(var i:int; i<target.length; i++) {
					if(target.getItemAt(i)[field] == search) {
						trace("search : " + search + ", rtn : " + i);
						return i;
					}
				}
				
			}
			trace("search : " + search + ", rtn : " + i);
			return 0;
		}	
		
		// 콤보박스의 idx를 찾기 위해서. 
		public static function cbIndexOf3(target:ArrayCollection, field:String, search:*):int
		{
			if(target != null) {
				for(var i:int; i<target.length; i++) {
					if(target.getItemAt(i)[field] == search) {
						return i;
					}
				}
			}
			return -1;
		}		
		
		
		// fild이름 없이 바로 array로 매핑 되었을경우. 
		public static function cbIndexOf4(target:ArrayCollection, search:String):int
		{
			if(target != null) {
				for(var i:int; i<target.length; i++) {
					if(target.getItemAt(i) == search) {
						return i;
					}
				}
			}
			return -1;
		}
		
		/***
		 * 콤보박스에 셋시킬 년도를 ac에 담아 리턴한다.
		 *  dv:prev(지난), next(미래로)
		 *  val : 표시할 년도
		 **/		 	
        public static function setYearAc(dv:String, val:int, ac:ArrayCollection):ArrayCollection{
        	var obj:Object;
        	var iYear:int = DateUtil.thisYear();
        	if(dv=='prev') {	        		
        		for(var i:int = 0; i<val; i++) {
        			obj = {};
        			obj.label = iYear-i; 
        			obj.data = iYear-i;
        			ac.addItem(obj);
        		}
        	}
        	return ac;
        }
	        						
        public static function setYearPrv(val:int):ArrayCollection{
        	var obj:Object;
        	var iYear:int = DateUtil.thisYear();
       		var ac:ArrayCollection = new ArrayCollection();
			for(var i:int = 0; i<val; i++) {
				obj = {};
				obj.label = iYear-i; 
				obj.data = iYear-i;
				ac.addItem(obj);
			}
        	return ac;
        }	        						
	        						
	     /***
		 *  startDay날부터 시작함. ex)20140501이 되면 true return;
		 * 	20140501부터 실행할 기능  0.8
		 *		if(canStartFunc(20140501) == true) {
					value1 = value1 * .8;	
				}
				else {
					value1 = value1 * .6;
				} 
		 **/	
		public static  function canStartFunc(startDay:int):Boolean
		{
			var nowDay:int = parseInt(DateUtil.toBasicString(new Date()) );	
			if(nowDay < startDay) {
				return false;
			}
			else {
				return true;
			}
		} 	        						
	        						
	}
	
}